home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / pcl / src-16f.lha / ldb / os-common.c < prev    next >
C/C++ Source or Header  |  1992-04-02  |  2KB  |  96 lines

  1. #include <stdio.h>
  2.  
  3. #include "ldb.h"
  4. #include "os.h"
  5.  
  6. void os_zero(addr, length)
  7. os_vm_address_t addr;
  8. os_vm_size_t length;
  9. {
  10.     os_vm_address_t block_start;
  11.     os_vm_size_t block_size;
  12.  
  13. #ifdef DEBUG
  14.     fprintf(stderr,";;; os_zero: addr: 0x%08x, len: 0x%08x\n",addr,length);
  15. #endif
  16.  
  17.     block_start=os_round_up_to_page(addr);
  18.  
  19.     length-=block_start-addr;
  20.     block_size=os_trunc_size_to_page(length);
  21.  
  22.     if(block_start>addr)
  23.     bzero((char *)addr,block_start-addr);
  24.     if(block_size<length)
  25.     bzero((char *)block_start+block_size,length-block_size);
  26.     
  27.     if (block_size != 0) {
  28.     /* Now deallocate and allocate the block so that it */
  29.     /* faults in  zero-filled. */
  30.  
  31.     os_invalidate(block_start,block_size);
  32.     addr=os_validate(block_start,block_size);
  33.  
  34.     if(addr==NULL || addr!=block_start)
  35.         fprintf(stderr,"os_zero: block moved, 0x%08x ==> 0x%08x!\n",block_start,addr);
  36.     }
  37. }
  38.  
  39. os_vm_address_t os_allocate(len)
  40. os_vm_size_t len;
  41. {
  42.     return os_validate((os_vm_address_t)NULL,len);
  43. }
  44.  
  45. os_vm_address_t os_allocate_at(addr,len)
  46. os_vm_address_t addr;
  47. os_vm_size_t len;
  48. {
  49.     return os_validate(addr, len);
  50. }
  51.  
  52. void os_deallocate(addr,len)
  53. os_vm_address_t addr;
  54. os_vm_size_t len;
  55. {
  56.     os_invalidate(addr,len);
  57. }
  58.  
  59. os_vm_address_t os_reallocate(addr,old_len,len)
  60. os_vm_address_t addr;
  61. os_vm_size_t old_len, len;
  62. {
  63.     addr=os_trunc_to_page(addr);
  64.     len=os_round_up_size_to_page(len);
  65.     old_len=os_round_up_size_to_page(old_len);
  66.  
  67.     if(addr==NULL)
  68.     return os_allocate(len);
  69.     else{
  70.     long len_diff=len-old_len;
  71.  
  72.     if(len_diff<0)
  73.         os_invalidate(addr+len,-len_diff);
  74.     else if(len_diff!=0){
  75.         os_vm_address_t new=os_validate(addr+old_len,len_diff);
  76.  
  77.         if(new==NULL || new!=addr+old_len){
  78.         if(new!=NULL)
  79.             /* allocated alright, but in the wrong place */
  80.             os_invalidate(new,len_diff);
  81.  
  82.         new=os_allocate(len);
  83.         
  84.         if(new!=NULL){
  85.             bcopy(addr,new,old_len);
  86.             os_invalidate(addr,old_len);
  87.         }
  88.         
  89.         addr=new;
  90.         }
  91.     }
  92.     
  93.     return addr;
  94.     }
  95. }
  96.